package org.erepublik.company;

import java.util.HashMap;

/**
 * Klasa reprezentujaca kazdy kraj, ktory jest w erepie.
 * 
 * @author Kacper Gorski 'Railman' railman85@gmail.com
 */
public enum ECountry implements Location {
    BELARUS(83, "Belarus", "BYR", "Belarus", EAlliance.NEW_COUNTRIES),
    CYPRUS(82, "Cyprus", "CYP", "Cyprus", EAlliance.NEW_COUNTRIES),
    MACEDONIA(79, "Republic-of-Macedonia-FYROM", "MKD", "Republic of Macedonia (FYROM)", EAlliance.NEW_COUNTRIES),
    MONTENEGRO(80, "Montenegro", "MEP", "Montenegro", EAlliance.NEW_COUNTRIES),
    NEW_ZELAND(84, "New-Zealand", "NZD", "New Zealand" , EAlliance.NEW_COUNTRIES),
    TAIWAN(81, "Republic-of-China-Taiwan", "TWD", "Republic of China (Taiwan)" , EAlliance.NEW_COUNTRIES),
    
	ARGENTINA(27, "Argentina", "ARS","Argentina", EAlliance.PHOENIX),
	AUSTRALIA(50, "Australia", "AUD","Australia", EAlliance.EDEN),
    AUSTRIA(33, "Austria", "ATS","Austria", EAlliance.NEUTRAL),
	BOSNIA(69, "Bosnia-Herzegovina", "BAM","Bosnia and Herzegovina", EAlliance.EDEN),
	BELGIUM(32, "Belgium", "BEF","Belgium", EAlliance.NEUTRAL),
	BULGARIA(42, "Bulgaria", "BGN","Bulgaria", EAlliance.PHOENIX),
	BOLIVIA(76, "Bolivia", "BOB","Bolivia", EAlliance.NEUTRAL),
	BRAZIL(9, "Brazil", "BRL","Brazil", EAlliance.PHOENIX),
	CANADA(23, "Canada", "CAD","Canada", EAlliance.EDEN),
	CHILE(64, "Chile", "CLP","Chile", EAlliance.NEUTRAL),
	CHINA(14, "China", "CNY","China", EAlliance.EDEN),
	COLOMBIA(78, "Colombia", "COP","Colombia", EAlliance.NEUTRAL),
	CROATIA(63, "Croatia", "HRK","Croatia", EAlliance.EDEN),
	CZECH(34, "Czech-Republic", "CZK","Czech Republic", EAlliance.NEUTRAL),
	DENMARK(55, "Denmark", "DKK", "Denmark", EAlliance.NEUTRAL),
	ESTONIA(70, "Estonia", "EEK", "Estonia", EAlliance.PHOENIX),
	FINLAND(39, "Finland", "FIM", "Finland", EAlliance.EDEN),
	FRANCE(11, "France", "FRF","France", EAlliance.PHOENIX),
	GERMANY(12, "Germany", "DEM","Germany", EAlliance.PHOENIX),
	GREECE(44, "Greece", "GRD","Greece", EAlliance.EDEN),
	HUNGARY(13, "Hungary", "HUF","Hungary", EAlliance.PHOENIX),
	INDIA(48, "India", "INR","India", EAlliance.NEUTRAL),
	INDONESIA(49, "Indonesia", "IDR","Indonesia", EAlliance.PHOENIX),
	IRAN(56, "Iran", "IRR","Iran", EAlliance.PHOENIX),
	IRELAND(54, "Ireland", "IEP","Ireland", EAlliance.NEUTRAL),
	ISRAEL(58, "Israel", "NIS","Israel", EAlliance.EDEN),
	ITALY(10, "Italy", "ITL","Italy", EAlliance.EDEN),
	JAPAN(45, "Japan", "JPY","Japan", EAlliance.NEUTRAL),
	LATVIA(71, "Latvia", "LVL","Latvia", EAlliance.NEUTRAL),
	LITHUANIA(72, "Lithuania", "LTL","Lithuania", EAlliance.PHOENIX),
	MALAYSIA(66, "Malaysia", "MYR","Malaysia", EAlliance.NEUTRAL),
	MEXICO(26, "Mexico", "MXN", "Mexico", EAlliance.NEUTRAL),
	NETHERLANDS(31, "Netherlands", "NLG","Netherlands", EAlliance.PHOENIX),
	NORTH_KOREA(73, "North-Korea", "KPW","North Korea", EAlliance.NEUTRAL),
	NORWAY(37, "Norway", "NOK","Norway", EAlliance.NEUTRAL),
	PAKISTAN(57, "Pakistan", "PKR","Pakistan", EAlliance.NEUTRAL),
	PARAGWAY(75, "Paraguay", "PYG","Paraguay", EAlliance.NEUTRAL),
	PERU(77, "Peru", "PEN","Peru", EAlliance.NEUTRAL),
	PHILIPPINES(67, "Philippines", "PHP","Philippines", EAlliance.NEUTRAL),
	POLAND(35, "Poland", "PLN","Poland", EAlliance.EDEN),
	PORTUGAL(53, "Portugal", "PTE","Portugal", EAlliance.PHOENIX),
	REPUBLIC_OF_MOLDOVIA(52, "Republic-of-Moldova", "MDL","Republic of Moldova", EAlliance.NEUTRAL),
	ROMANIA(1, "Romania", "RON","Romania", EAlliance.EDEN),
	RUSSIA(41, "Russia", "RUB","Russia", EAlliance.PHOENIX),
	SERBIA(65, "Serbia", "RSD","Serbia", EAlliance.PHOENIX),
	SINGAPORE(68, "Singapore", "SGD","Singapore", EAlliance.NEUTRAL),
	SLOVAKIA(36, "Slovakia", "SKK","Slovakia", EAlliance.NEUTRAL),
	SLOVENIA(61, "Slovenia", "SIT","Slovenia", EAlliance.PHOENIX),
	SOUTH_AFRICA(51, "South-Africa", "ZAR", "South Africa", EAlliance.NEUTRAL),
	SOUTH_KOREA(47, "South-Korea", "KRW","South Korea", EAlliance.NEUTRAL),
	SPAIN(15, "Spain", "ESP","Spain", EAlliance.EDEN),
	SWEDEN(38, "Sweden", "SEK","Sweden", EAlliance.EDEN),
	SWITZERLAND(30, "Switzerland", "CHF","Switzerland", EAlliance.NEUTRAL),
	THAILAND(59, "Thailand", "THB","Thailand", EAlliance.NEUTRAL),
	TURKEY(43, "Turkey", "TRY","Turkey", EAlliance.PHOENIX),
	UKRAINE(40, "Ukraine", "UAH","Ukraine", EAlliance.NEUTRAL),
	UNITED_KINGDOM(29, "United-Kingdom", "GBP","United Kingdom", EAlliance.PHOENIX),
	URUGWAY(74, "Uruguay", "UYU","Uruguay", EAlliance.NEUTRAL),
	USA(24, "USA", "USD","USA", EAlliance.EDEN),
	VENEZUELA(28, "Venezuela", "VEB","Venezuela", EAlliance.NEUTRAL);
	
	private int erepublikId;
	private String name;
	private String urlName;
	private static HashMap<String, ECountry> map = null;
	private static HashMap<Integer, ECountry> idmap = null;
	private String currencyName;
	private EAlliance alliance;

	/**
	 * @param erepublikId - id, pod jakim jest dany kraj w erepublik.com
	 * @param urlName - nazwa kraju wykorzystywana jako parametr na stronie erepubliko.com
	 * @param currencyName - skrot nazwy lokalnej waluty
	 * @param name - nazwa kraju
	 */
	ECountry(int erepublikId, String urlName, String currencyName, String name, EAlliance alliance) {
		this.erepublikId = erepublikId;
		this.setUrlName(urlName);
		this.name = name;
		this.alliance = alliance;
		this.currencyName = currencyName;
	}

	public EAlliance getAlliance() {
	    return alliance;
	}
	
	/**
	 * @return id biezacego kraju, pod jakim wystepuje on na stronie erpublik.com
	 */
	public int getErepublikId() {
		return erepublikId;
	}

	/**
	 * @return Pelna nazwa podanego kraju
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name - nazwa kraju
	 * @return zwraca gotowy enum dla kraju o podanej nazwie. Jesli nei ma takiego kraju, to zwroci null
	 */
	public static ECountry getCountryByName(String name) {
		if (map == null)
			initMap();
		return map.get(name);
	}
	
	public static ECountry getCountryById(int id) {
	    if (idmap == null)
	        initidMap();
	    return idmap.get(id);
	}
	

	// inicjalizacja potrzebnych struktur danych
	private static void initMap() {
		map = new HashMap<String, ECountry>();
		for (ECountry country : ECountry.values()) {
			map.put(country.getName(), country);
		}

	}
	
	   // inicjalizacja potrzebnych struktur danych
    private static void initidMap() {
        idmap = new HashMap<Integer, ECountry>();
        for (ECountry country : ECountry.values()) {
            idmap.put(country.getErepublikId(), country);
        }

    }
	

	/**
	 * @return skrotowa nazwa waluty obowiazujacej w danym kraju
	 */
	public String getCurrencyName() {
		return currencyName;
	}


	public void setUrlName(String urlName) {
		this.urlName = urlName;
	}

	 /**
     * @return - nazwa kraju, jaka jest przekazywana w urlach na stronie erepublik.com
     */
	public String getUrlName() {
		return urlName;
	}

    @Override
    public String getColor() {
        return getAlliance().getColor();
    }

    @Override
    public String getUrl() {
        return "http://www.erepublik.com/images/flags/M/"+getUrlName()+".gif";
    }
    
    @Override
    public String getType() {
        return "Country";
    }
	
}
